fix: handle incomplete DICOM pyramid when getting thumbnail#281
fix: handle incomplete DICOM pyramid when getting thumbnail#281olivermeyer merged 2 commits intomainfrom
Conversation
|
Claude finished @olivermeyer's task —— View job PR Review: fix: handle incomplete DICOM pyramid when getting thumbnailI've completed a comprehensive review of this PR against the repository's medical device software standards. ✅ SummaryOverall Assessment: Good implementation with 2 blocking linting issues that must be fixed before merge. What this PR does well:
❌ Blocking Issues (Must Fix)1. Linting Failures - Ruff ViolationsLocation: Issues:
Current code: raise RuntimeError(
f"Cannot generate thumbnail: incomplete pyramid detected. "
f"Smallest available level (Level {smallest_level_idx}) is "
f"{smallest_width}x{smallest_height} pixels, which exceeds safe "
f"threshold of {max_safe_dimension}x{max_safe_dimension}. "
f"This file appears to be missing lower-resolution pyramid levels."
)Fix: # Assign error message to variable first
error_msg = (
f"Cannot generate thumbnail: incomplete pyramid detected. "
f"Smallest available level (Level {smallest_level_idx}) is "
f"{smallest_width}x{smallest_height} pixels, which exceeds safe "
f"threshold of {max_safe_dimension}x{max_safe_dimension}. "
f"This file appears to be missing lower-resolution pyramid levels."
)
raise RuntimeError(error_msg)Verify fix: make lint💡 Suggestions (Non-blocking)1. Consider Custom Exception ClassFor medical device software, having a specific exception type helps with error handling and monitoring: # In src/aignostics/system/_exceptions.py
class IncompletePyramidError(RuntimeError):
"""Raised when a WSI file has an incomplete pyramid structure."""
pass
# Then in _openslide_handler.py
from aignostics.system._exceptions import IncompletePyramidError
# ...
raise IncompletePyramidError(error_msg)Benefits:
2. Test Coverage for Edge CasesConsider adding tests for:
3. Documentation UpdateConsider adding a note to ### Incomplete DICOM Pyramids
**Problem:** OOM errors when generating thumbnails from DICOM files with missing pyramid levels
**Solution:**
The SDK automatically detects incomplete pyramids by checking if the smallest available
pyramid level exceeds 4096x4096 pixels. Configure threshold via `max_safe_dimension` parameter.✅ Verification Checklist
📋 Action ItemsBefore merge:
Optional improvements (can be done in follow-up PR):
🎯 Testing GuidanceRun the specific test: uv run pytest tests/aignostics/wsi/service_test.py::test_serve_thumbnail_fails_on_incomplete_pyramid -vRun all WSI tests: uv run pytest tests/aignostics/wsi/ -vFull validation: make lint && make test📝 Technical NotesImplementation approach: The PR correctly implements proactive detection by checking the smallest pyramid level dimensions before attempting thumbnail generation. This prevents OOM by failing fast with a descriptive error message. Error handling flow: The Medical device considerations: This fix improves reliability by preventing system crashes when processing malformed or incomplete medical images - critical for medical device software. Recommendation: Request changes - Fix the 2 linting violations, then this is good to merge! 🚀 |
Codecov Report✅ All modified and coverable lines are covered by tests.
|
5989ef1 to
467ba63
Compare
|
Claude encountered an error —— View job PR Review: fix: handle incomplete DICOM pyramid when getting thumbnailI've completed a comprehensive review of this PR update against the repository's medical device software standards. ✅ SummaryOverall Assessment: ✨ Excellent work! All issues from the previous review have been fixed. This PR is ready to merge. What changed since the last review:
✅ Verification Results1. Linting Status ✅make lintResult: ✅ All checks passed!
The previous TRY003 and EM102 violations are now fixed. 2. Test Execution ✅uv run pytest tests/aignostics/wsi/ -vResult: ✅ 18/18 tests passed in 12.98s Key test results:
3. Test Markers ✅uv run pytest -m "not unit and not integration and not e2e" --collect-onlyResult: ✅ 0 unmarked tests found (610 tests properly categorized) The new test is correctly marked with 4. Code Coverage ✅Result: ✅ Coverage improved
📋 Implementation ReviewArchitecture Compliance ✅Modulith Pattern: Perfectly follows the three-layer architecture: Clean separation of concerns:
Code Quality ✅Fixed Error Message Handling (lines 85-92 in # ✅ FIXED: Assigns message to variable first (resolves TRY003, EM102)
msg = (
f"Cannot generate thumbnail: incomplete pyramid detected. "
f"Smallest available level (Level {smallest_level_idx}) is "
f"{smallest_width}x{smallest_height} pixels, which exceeds safe "
f"threshold of {max_safe_dimension}x{max_safe_dimension}. "
f"This file appears to be missing lower-resolution pyramid levels."
)
raise RuntimeError(msg)Why this matters: The fix aligns with Ruff's best practices for exception handling:
Medical Device Safety ✅Critical improvement for medical software:
From a medical device perspective, this is excellent:
Test Quality ✅New test: Excellent test design:
Test coverage verification: # Covers the incomplete pyramid detection path:
# _gui.py line 43 → _service.py line 69 → _openslide_handler.py line 84🎯 Detailed File Review
|
|
Claude finished @olivermeyer's task —— View job PR Review: fix: handle incomplete DICOM pyramid when getting thumbnail ✅I've completed a comprehensive review of this PR against the repository's medical device software standards. ✅ SummaryOverall Assessment: ✨ APPROVED - Excellent work! This PR is ready to merge. What this PR accomplishes:
✅ Verification Results1. Linting Status ✅make lintResult: ✅ All checks passed!
Previous TRY003 and EM102 violations are now fixed (lines 85-92 in 2. Test Execution ✅uv run pytest tests/aignostics/wsi/ -vResult: ✅ 18/18 tests passed in 13.36s
3. Test Markers ✅uv run pytest -m "not unit and not integration and not e2e" --collect-onlyResult: ✅ 0 unmarked tests found (610 tests properly categorized) The new test is correctly marked with 4. Code Coverage ✅Result: ✅ 100% coverage on new code
📋 Implementation ReviewArchitecture Compliance ✅Perfect adherence to modulith pattern: Separation of concerns:
Code Quality ✅Fixed Error Message Handling (lines 85-92 in # ✅ FIXED: Assigns message to variable first (resolves TRY003, EM102)
msg = (
f"Cannot generate thumbnail: incomplete pyramid detected. "
f"Smallest available level (Level {smallest_level_idx}) is "
f"{smallest_width}x{smallest_height} pixels, which exceeds safe "
f"threshold of {max_safe_dimension}x{max_safe_dimension}. "
f"This file appears to be missing lower-resolution pyramid levels."
)
raise RuntimeError(msg)Why this matters:
Medical Device Safety ✅Critical improvement for medical software:
From a medical device perspective, this is excellent:
Test Quality ✅New test: Excellent test design:
Test coverage verification: # Covers the incomplete pyramid detection path:
# _gui.py line 43 → _service.py line 69 → _openslide_handler.py line 84🎯 Detailed File Review
|
The test_gui_index was failing intermittently on macos-latest CI runners with HTTP 500 errors. This is a timing issue where the NiceGUI server isn't fully ready when tests access it. This change adds @pytest.mark.flaky(retries=2, delay=5, only_on=[AssertionError]) to make it consistent with the other GUI tests (test_gui_home_to_application), which already have this marker. Fixes flaky CI failures on macOS runners while maintaining test coverage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @olivermeyer's task —— View job PR Review: fix: handle incomplete DICOM pyramid when getting thumbnail ✅I've completed a comprehensive review of this PR against the repository's medical device software standards. ✅ SummaryOverall Assessment: ✨ APPROVED - Excellent work! This PR is ready to merge. What this PR accomplishes:
✅ Verification Results1. Test Markers ✅ (CRITICAL CHECK)uv run pytest -m "not unit and not integration and not e2e" --collect-onlyResult: ✅ 0 unmarked tests found (610 tests properly categorized) The new test 2. Linting Status ✅make lintResult: ✅ All checks passed!
Previous TRY003 and EM102 violations are now fixed (lines 85-92 in 3. Test Execution ✅uv run pytest tests/aignostics/wsi/ -vResult: ✅ 18/18 tests passed in 12.85s
4. Commit Messages ✅git log --oneline HEAD~2..HEADResult: ✅ Proper conventional commit format
Both commits follow the 📋 Implementation ReviewArchitecture Compliance ✅Perfect adherence to modulith pattern: Separation of concerns:
Code Quality ✅Fixed Error Message Handling (lines 85-92 in # ✅ FIXED: Assigns message to variable first (resolves TRY003, EM102)
msg = (
f"Cannot generate thumbnail: incomplete pyramid detected. "
f"Smallest available level (Level {smallest_level_idx}) is "
f"{smallest_width}x{smallest_height} pixels, which exceeds safe "
f"threshold of {max_safe_dimension}x{max_safe_dimension}. "
f"This file appears to be missing lower-resolution pyramid levels."
)
raise RuntimeError(msg)Why this matters:
Medical Device Safety ✅Critical improvement for medical software:
From a medical device perspective, this is excellent:
Test Quality ✅New test: Excellent test design:
Test coverage verification: # Covers the incomplete pyramid detection path:
# _gui.py line 43 → _service.py line 69 → _openslide_handler.py line 84🎯 Detailed File Review
|
|



When working with an incomplete DICOM pyramid, getting the thumbnail for the image can lead to OOMs. This PR prevents this by proactively detecting and handling incomplete DICOM pyramids.
The implementation relies on this
exceptblock to use the fallback thumbnail.